var auth_app = angular.module("authentication",[]);

auth_app.factory("authentication", function($http,$q){
	var baseurl = "/authentication/";
	function getUser(){
		var deferred = $q.defer();
		$http({method:"GET", url:"/getUser",data:{name:$scope.username}}).then(function(result){
			console.log("Result of Get User = ",result.data);
			var result = result.data;
			if(result === 'Success'){
				$scope.messageText = "User details are available";
			}else{
				$scope.messageText = "Username is not exist";	
			}
		});
	}
	function createUser(){
		var deferred = $q.defer();
		
	}
});
	


auth_app.controller('loginController', ['$scope','$http','$location' ,function($scope,$http){
	$scope.userName = "";
	$scope.password = "";
    console.log("TEST");
	$scope.authenticateUser = function (){
		console.log("inside method");
		console.log($scope);
		var userName = $scope.session.username;
		var password = $scope.session.password;
		console.log("User Name = ",userName);
		console.log("Password = ",password);

		$http({method:"GET", url:"/authentication/getUser",data:{name:$scope.username}}).then(function(result){
			console.log("Result of Get User = ",result.data);
			var result = result.data;
			if(result === 'Success'){
				$scope.messageText = "User details are available";
			}else{
				$scope.messageText = "Username is not exist";	
			}
		});
	};
	$scope.createUser = function(){
		console.log("Session Obj",$scope.session);
        var config = {params: {}};
        var postData = {
            userName : $scope.session.username,
            firstName : $scope.session.firstName,
            lastName : $scope.session.lastName,
            password : $scope.session.password,
            mobileNo : $scope.session.mobileNo,
            emailId : $scope.session.emailId
        }
        $http.post('/authentication/createUser',postData,config
        ).success( function (data,status,header,config){

        }).error(function (data,status,header,config){

        });
		/*$http({method:"POST", url:"/authentication/createUser",
			data:{userName : $scope.session.username,
			firstName : $scope.session.firstName,
			lastName : $scope.session.lastName,
			password : $scope.session.password,
			mobileNo : $scope.session.mobileNo,
			emailId : $scope.session.emailId
			}}).then(function(result){
			console.log("Result of Get User = ",result.data);
			var result_data = result.data;
			if(result_data === 'Success'){
				$scope.messageText = "User details are available";
			}else{
				$scope.messageText = "Username is not exist";	
			}
		});*/
	};
}]);